home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / lib / C / atoms.c next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  4.1 KB  |  172 lines

  1. /* 
  2.  * atoms.c
  3.  *    - lexical token lookup for reserved words in postquel
  4.  */
  5.  
  6. /*
  7.  * List of (keyword-name, keyword-token-value) pairs.
  8.  *
  9.  * NOTE: This list must be sorted, because binary
  10.  *     search is used to locate entries.
  11.  */
  12.  
  13. #include <ctype.h>
  14. #include "tmp/c.h"
  15.  
  16. RcsId("$Header: /private/postgres/src/lib/C/RCS/atoms.c,v 1.26 1992/07/06 05:03:45 mao Exp $");
  17.  
  18. #include "nodes/pg_lisp.h"
  19. #include "parser/atoms.h"
  20. #include "parser/parse.h"
  21. #include "utils/log.h"
  22.  
  23. ScanKeyword    ScanKeywords[] = {
  24.     /* name            value        */
  25.     { "ISNULL",             ISNULL          },
  26.     { "NOTNULL",            NOTNULL         },
  27.     { "NULL",        PNULL        },
  28.     { "abort",        ABORT_TRANS    },
  29.     { "addattr",        ADD_ATTR    },
  30.     { "after",        AFTER        },
  31.     { "aggregate",          AGGREGATE       },
  32.     { "all",        ALL        },
  33.     { "always",        ALWAYS        },
  34.     { "and",        AND        },
  35.     { "append",        APPEND        },
  36.     { "arch_store",        ARCH_STORE    },
  37.     { "archive",        ARCHIVE        },
  38.     { "arg",        ARG        },
  39.         { "as",                 AS              },
  40.     { "ascending",        ASCENDING    },
  41.     { "attachas",        ATTACH_AS    },
  42.     { "backward",        BACKWARD    },
  43.     { "before",        BEFORE        },
  44.     { "begin",        BEGIN_TRANS    },
  45.     { "binary",        BINARY        },
  46.     { "by",            BY        },
  47.     { "cfunction",        C_FUNCTION    },
  48.     { "close",        CLOSE        },
  49.     { "cluster",        CLUSTER        },
  50.     { "copy",        COPY        },
  51.     { "create",        CREATE        },
  52.     { "createdb",        CREATEDB    },
  53.     { "current",        CURRENT        },
  54.     { "define",        DEFINE        },
  55.     { "delete",        DELETE        },
  56.     { "demand",        DEMAND        },
  57.     { "descending",        DESCENDING    },
  58.     { "destroy",        DESTROY        },
  59.     { "destroydb",        DESTROYDB    },
  60.     { "do",            DO        },
  61.     { "empty",        EMPTY        },
  62.     { "end",        END_TRANS    },
  63.     { "execute",        EXECUTE        },
  64.     { "fetch",        FETCH        },
  65.     { "forward",        FORWARD        },
  66.     { "from",        FROM        },
  67.     { "function",        FUNCTION    },
  68.     { "heavy",        HEAVY        },
  69.     { "in",            IN        },
  70.     { "index",        INDEX        },
  71.     { "indexable",        INDEXABLE    },
  72.     { "inherits",        INHERITS    },
  73.     { "input_proc",        INPUTPROC    },
  74.     { "instance",        P_TUPLE        },
  75.     { "instead",        INSTEAD        },
  76.     { "intersect",        INTERSECT    },
  77.     { "into",        INTO        },
  78.     { "intotemp",           INTOTEMP        },
  79.     { "iportal",            IPORTAL         },
  80.     { "is",            IS        },
  81.     { "key",        KEY        },
  82.     { "leftouter",        LEFTOUTER    },
  83.     { "light",        LIGHT        },
  84.     { "listen",             LISTEN          },
  85.     { "load",               LOAD            },
  86.     { "merge",        MERGE        },
  87.     { "move",        MOVE        },
  88.     { "never",        NEVER        },
  89.     { "new",        NEW        },
  90.     { "none",        NONE        },
  91.     { "nonulls",        NONULLS        },
  92.     { "not",        NOT        },
  93.     { "notify",             NOTIFY          },
  94.     { "on",            ON        },
  95.     { "once",        ONCE        },
  96.     { "operator",        OPERATOR    },
  97.     { "or",            OR        },
  98.     { "output_proc",    OUTPUTPROC    },
  99.     { "parallel",        PARALLEL    },
  100.     { "pfunction",        P_FUNCTION    },
  101.     { "portal",        PORTAL        },
  102.     { "postquel",        POSTQUEL    },
  103.     { "priority",        PRIORITY    },
  104.     { "purge",        PURGE        },
  105.     { "quel",        QUEL        },
  106.     { "relation",        RELATION    },
  107.     { "remove",        REMOVE        },
  108.     { "rename",        RENAME        },
  109.     { "replace",        REPLACE        },
  110.     { "retrieve",        RETRIEVE    },
  111.     { "returns",        RETURNS        },
  112.     { "rewrite",        REWRITE        },
  113.     { "rightouter",        RIGHTOUTER    },
  114.     { "rule",        RULE        },
  115.     { "setof",        SETOF        },
  116.     { "sort",        SORT        },
  117.     { "stdin",        STDIN        },
  118.     { "stdout",        STDOUT        },
  119.     { "store",        STORE        },
  120.     { "to",            TO        },
  121.     { "transaction",    TRANSACTION    },
  122.     { "type",        P_TYPE        },
  123.     { "union",        UNION        },
  124.     { "unique",        UNIQUE        },
  125.     { "using",        USING        },
  126.     { "vacuum",        VACUUM        },
  127.     { "version",        NEWVERSION    },
  128.     { "view",        VIEW        },
  129.     { "where",        WHERE        },
  130.     { "with",        WITH        },
  131. };
  132.  
  133. ScanKeyword *
  134. ScanKeywordLookup(text)
  135.     char    *text;
  136. {
  137.     ScanKeyword    *low    = &ScanKeywords[0];
  138.     ScanKeyword    *high    = endof(ScanKeywords) - 1;
  139.     ScanKeyword    *middle;
  140.     int        difference;
  141.  
  142.     while (low <= high) {
  143.         middle = low + (high - low) / 2;
  144.         difference = strcmp(middle->name, text);
  145.         if (difference == 0)
  146.             return (middle);
  147.         else if (difference < 0)
  148.             low = middle + 1;
  149.         else
  150.             high = middle - 1;
  151.     }
  152.  
  153.     return (NULL);
  154. }
  155.  
  156. String
  157. AtomValueGetString ( atomval )
  158.      int atomval;
  159. {
  160.     ScanKeyword *low = &ScanKeywords[0];
  161.     ScanKeyword *high = endof(ScanKeywords) - 1;
  162.     int keyword_list_length = (high-low);
  163.     int i;
  164.  
  165.     for (i=0; i < keyword_list_length  ; i++ )
  166.       if (ScanKeywords[i].value == atomval )
  167.     return(ScanKeywords[i].name);
  168.     
  169.     elog(WARN,"AtomGetString called with bogus atom # : %d", atomval );
  170.     return(NULL);
  171. }
  172.